<template>
  <div>
    <div class="home-container">
      <!-- <nav-menu class="navtop"></nav-menu> -->
      <div>
        <el-carousel
          indicator-position="none"
          arrow="nerver"
          :interval="5000"
          height="100%"
          class="imgst"
        >
          <el-carousel-item v-for="item in blogInfo.covers" :key="item">
            <div class="item-box">
              <!-- <img src="../assets/img/sea.jpg" class="carimg" /> -->
              <!-- <img :src="item" class="carimg" /> -->

              <div class="desc-box">
                <h1 class="hhh">{{ blogInfo.title }}</h1>
                <p class="ppp">
                  {{ blogInfo.desc }}
                  <span class="typed-cursor">|</span>
                </p>
              </div>

              <!-- <div class="scroll-down" @click="scrollDown">
              <i color="#fff" class="scroll-down-effects el-icon-caret-bottom"> </i>
            </div> -->
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="scroll-down" @click="scrollDown">
        <i color="#fff" class="scroll-down-effects el-icon-caret-bottom"> </i>
      </div>
    </div>
    <el-row :gutter="20">
      <el-col :span="12" :offset="4">
        <article-item
          v-for="article in pageInfo.records"
          :key="article.id"
          :article="article"
        ></article-item>
        <!-- <infinite-loading @infinite="infiniteHandler">
          <div slot="no-more"></div>
        </infinite-loading> -->
        <el-pagination
          class="white-list-tool"
          background
          @current-change="handleCurrentChange"
          :current-page.sync="pageInfo.current"
          :page-size="pageInfo.size"
          layout="prev, pager, next, jumper"
          :total="pageInfo.total"
          :hide-on-single-page="true"
        ></el-pagination>
      </el-col>
      <el-col :span="4">
        <blog-info></blog-info>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import request from "@/http/request";
import { mapState } from "vuex";

export default {
  name: "Home",
  data() {
    return {
      // data 中的 pageInfo 表示一页文章信息
      pageInfo: {},
    };
  },
  computed: mapState(["blogInfo"]),
  components: {
    BlogInfo: () => import("@/components/BlogInfo.vue"),
    ArticleItem: () => import("@/components/ArticleItem.vue"),
    // NavMenu: () => import("@/components/NavMenu.vue"),
  },
  // created 函数在实例已创建，模板还未渲染的时候执行，用于获取文章信息，如果出现错误就弹出提示信息
  created() {
    this.getPageArticles(1, 5);
  },
  methods: {
    handleCurrentChange(page) {
      this.getPageArticles(page, 5);
    },
    getPageArticles(page, limit) {
      request
        .getArticles(page, limit)
        .then((res) => {
          if (res.code === 0) {
            this.pageInfo = res.data;
          } else {
            this.$notify.error({
              title: "提示",
              message: res.msg,
            });
          }
        })
        .catch((err) => {
          console.log(err);
          this.$notify.error({
            title: "提示",
            message: "网络繁忙，文章获取失败",
          });
        });
    },
    scrollDown() {
      window.scrollTo({
        behavior: "smooth",
        top: document.documentElement.clientHeight,
      });
      // console.log(document.documentElement.clientHeight);
      // window.scrollTo(0, document.documentElement.clientHeight);
      // window.scrollTo(0, 0);
    },
  },
};
</script>

<style scoped>
.typed-cursor {
  opacity: 0.1;
  animation: blink 0.7s infinite;
}
@keyframes blink {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

h1 {
  font-size: 2.4rem;
}

.el-carousel {
  z-index: 0;
}

.scroll-down {
  cursor: pointer;
  /* position: absolute; */
  position: relative;
  bottom: 4px;
  width: 100%;
  text-align: center;

  top: -160px;
}
.scroll-down i {
  font-size: 3rem;
}

.scroll-down-effects {
  color: #eee !important;
  text-align: center;
  text-shadow: 0.1rem 0.1rem 0.2rem rgba(0, 0, 0, 0.15);
  line-height: 1.5;
  display: inline-block;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  animation: scroll-down-effect 1.5s infinite;
}
@keyframes scroll-down-effect {
  0% {
    top: 0;
    opacity: 0.4;
    filter: alpha(opacity=40);
  }
  50% {
    top: -16px;
    opacity: 1;
    filter: none;
  }
  100% {
    top: 0;
    opacity: 0.4;
    filter: alpha(opacity=40);
  }
}

.imgst {
  /* position: absolute; */
  top: -60px;
  left: 0;
  right: 0;
  height: 110vh;
  background-attachment: fixed;
  /* text-align: center; */
  /* color: #fff !important; */
  /* animation: header-effect 1s; */

  /* background-attachment: local;
  background-position: center;
  background-repeat: no-repeat; */
  background-color: rgba(0, 0, 0, 0.6);
  /* opacity: 0.6; */
}

.home-container {
  z-index: -9;
  height: 100%;
  width: 100%;
  /* position: absolute; */
  overflow-x: hidden;
}
.el-pagination {
  margin: 20px 0;
  text-align: center;
}

.item-box {
  position: relative;
  width: 100%;
  height: 100%;
}

.carimg {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  object-fit: cover;
  /* opacity: 0.8; */
  position: fixed;
  z-index: -9;
}

.desc-box {
  position: absolute;
  bottom: 0;
  left: 50%;
  top: 50%;
  width: 500px;
  height: 40px;
  margin-left: -250px;
  margin-top: -50px;
  text-align: center;
  color: #eee;
  padding: 21px;
  /* font-size: 3.2rem; */
  /* font-size: 1.8rem; */
}

.ppp {
  padding: 6px;
  font-size: 1.6rem;
}

.hhh {
  font-size: 3.2rem;
}

.el-card {
  margin-top: 20px;
}

.article-info {
  margin-top: 10px;
  color: #909399;
  font-size: 13px;
}

.article-icon,
.article-icon .tag {
  color: #909399;
  font-size: 13px;
  margin-right: 10px;
  text-decoration: none;
}

.article-icon .tag:hover {
  color: #409eff;
  cursor: pointer;
}

.tabloid {
  color: #606266;
  font-size: 14px;
  margin-bottom: 10px;
}


/* // page-sizes选择器 */
::v-deep .el-select-dropdown__item li{
  background-color:transparent !important;
}
/* // prev和next箭头的样式 */
::v-deep .el-pagination .btn-next,
::v-deep .el-pagination .btn-prev{
  background:transparent !important;
  background-color:transparent !important;
}
/* // prev和next箭头disabled的样式 */
::v-deep .el-pagination button:disabled {
  background-color:transparent !important;
}
/* // 页码样式 */
::v-deep .el-pager li{
  background-color:transparent !important;
}
/* // active的页码样式 */
::v-deep .el-pager li.active{
  color: #267aff !important;
}
</style>

